package org.apaydin.widget;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.List;

public class SpinnerArrayAdapter<T> extends ArrayAdapter<T> {

    private final ToString<T> textViewToString;
    private final ToString<T> dropDownViewToString;

    public SpinnerArrayAdapter(Context context, int textViewResourceId, int dropDownViewResource, List<T> objects, ToString<T> textViewToString, ToString<T> dropDownViewToString) {
        super(context, textViewResourceId, objects);
        this.textViewToString = textViewToString;
        this.dropDownViewToString = dropDownViewToString;
        setDropDownViewResource(dropDownViewResource);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        TextView view = (TextView) super.getView(position, convertView, parent);
        view.setText(textViewToString.toString(getItem(position)));
        return view;
    }

    @Override
    public View getDropDownView(int position, View convertView, ViewGroup parent) {
        TextView view = (TextView) super.getDropDownView(position, convertView, parent);
        view.setText(dropDownViewToString.toString(getItem(position)));
        return view;
    }
}
